/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_PLANE_H
#define M_PLANE_H

#include "vector3.h"
#include "common.h"

namespace Engine
{
	/**
	*   Point position relative plane.
	*/
	enum PointPos
	{
		POINT_IN_FRONT_OF_PLANE = 0,
		POINT_BEHIND_PLANE = 1,
		POINT_ON_PLANE = 2
	};

	/**
	*    Helper class for culling.
	*    When create plane manual set "d" as negative
	*/
	class Plane
	{
	public:
		Plane():a(0),b(0),c(0),d(0){}

		Plane(REAL ai,REAL bi,REAL ci,REAL di):a(ai),b(bi),c(ci),d(di){}

		REAL DotCoord(Vector3<REAL> vec)const {return (a*vec.x + b*vec.y + c*vec.z + d);}

		void Normalize(){ Vector3<REAL> normal(a,b,c); d /= normal.Normalise(); a = normal.x; b = normal.y; c = normal.z; }

		/**
		*   Detect where point is relative this plane.
		*/
		PointPos ClassifyPoint(const Vector3<REAL>& point)const;

	public:
		REAL a;
		REAL b;
		REAL c;
		REAL d;
	};
}

#endif
